package com.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.entity.Category;
import com.mapper.CategoryMapper;
import com.service.CategoryService;

@Service
public class CategoryServiceImpl implements CategoryService{
	@Resource
	private CategoryMapper categoryMapper;
	
	@Cacheable(value = "cacheArticle")
	public List<Category> listCategory() {
		return categoryMapper.listCategory();
	}

	public List<Category> listAndcountCategory() {
		List<Category> listCategory = categoryMapper.listCategory();
		for(Category c:listCategory) {//将分类表id放出来计算文章数量再放入Category表中
			Integer Categoryid = c.getCategoryId();
			Integer countArticle = categoryMapper.CountAticle(Categoryid);	
			c.setArticleCount(countArticle);
		}
		return listCategory;
	}
	
	public void addCategory(Category category) {
		categoryMapper.addCategory(category);
		
	}


	
	public void deleteCategory(Integer id) {
		categoryMapper.deleteCategory(id);
		
	}

	
	public Category getCategoryById(Integer id) {
		return categoryMapper.getCategoryById(id);
		
	}

}







